package com.erp.domain;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.activiti.engine.repository.ProcessDefinition;

import com.erp.dto.ProcessDeployment;

@Entity
@Table(name = "t_procdep")
public class TProcessDeployment {
	private Integer id;
	private Integer state;
	private String procDefId;
	private String procInstId;
	private String key;
	private String name;
	private Integer version;
	private String description;
	private Date deployTime;
	private TUser tDeployUser;

	public TProcessDeployment() {
	}

	/**
	 * 从流程定义接口获取需要的属性，其中部署人需要手动写入
	 * 
	 * @param procDef
	 *            流程定义接口
	 */
	public TProcessDeployment(ProcessDefinition procDef) {
		this.procDefId = procDef.getId();
		this.state = procDef.isSuspended() ? 0 : 1;
		this.key = procDef.getKey();
		this.name = procDef.getName();
		this.version = procDef.getVersion();
		this.description = procDef.getDescription();
		this.deployTime = new Date();
	}

	public TProcessDeployment(ProcessDeployment procDep) {
		this.id = procDep.getId();
		this.state = procDep.getState();
		this.procDefId = procDep.getProcDefId();
		this.key = procDep.getKey();
		this.name = procDep.getName();
		this.version = procDep.getVersion();
		this.description = procDep.getDescription();
		this.procInstId = procDep.getProcInstId();
		this.deployTime = procDep.getDeployTime();
		this.tDeployUser = new TUser(procDep.getDeployUser());
	}

	@Id
	@GeneratedValue
	@Column(name = "id")
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	@Column(name = "state")
	public Integer getState() {
		return state;
	}

	public void setState(Integer state) {
		this.state = state;
	}

	@Column(name = "procdef_id")
	public String getProcDefId() {
		return procDefId;
	}

	public void setProcDefId(String procDefId) {
		this.procDefId = procDefId;
	}

	@Column(name = "key_")
	public String getKey() {
		return key;
	}

	public void setKey(String key) {
		this.key = key;
	}

	@Column(name = "name_")
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column(name = "version_")
	public Integer getVersion() {
		return version;
	}

	public void setVersion(Integer version) {
		this.version = version;
	}

	@Column(name = "description")
	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	@Column(name = "procinst_id")
	public String getProcInstId() {
		return procInstId;
	}

	public void setProcInstId(String procInstId) {
		this.procInstId = procInstId;
	}

	@Column(name = "deploy_time")
	public Date getDeployTime() {
		return deployTime;
	}

	public void setDeployTime(Date deployTime) {
		this.deployTime = deployTime;
	}

	/**
	 * 本类与TUser是多对一单向关系
	 * 
	 * @return
	 */
	@ManyToOne
	@JoinColumn(name = "user_id")
	public TUser gettDeployUser() {
		return tDeployUser;
	}

	public void settDeployUser(TUser tDeployUser) {
		this.tDeployUser = tDeployUser;
	}

}
